#include "Delay_LCD.h"
#include "lcd.h"
#include "gui.h"
#include "Key_change.h"

#define DEBOUNCE_DELAY 30 // ??????(??:ms)
#define DEBOUNCE_DELAY_TIME 1500 // ??????(??:ms)

Event Event_Flag;

extern StateMachine sm;

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
	uint8_t i;
	switch (GPIO_Pin) 
	{
		case GPIO_PIN_2:
			Event_Flag = EVENT_UP;//UP
			break;

		case GPIO_PIN_3:
			Event_Flag = EVENT_LEFT;//LEFT
			break;

		case GPIO_PIN_4:
			Event_Flag = EVENT_RIGHT;//RIGHT
			break;
		
		case GPIO_PIN_5:
			Event_Flag = EVENT_DOWN;//DOWM
			break;
		
		case GPIO_PIN_6:
			Event_Flag = EVENT_IN;//IN
			break;

		default:
			Event_Flag = EVENT_UP;//UP
			break;
	}
	uint8_t count;
	
	for(i = 0;i < DEBOUNCE_DELAY;i++)
	{
		if(HAL_GPIO_ReadPin(GPIOE,GPIO_Pin) == RESET)
			count++;
		delay_us(DEBOUNCE_DELAY_TIME);
	}
	if(count >= 20)
		process_event(&sm, Event_Flag);
	count = 0;
}


